package com.acme.bankapp.domain.bank;

import com.acme.bankapp.exceptions.bank.ClientNotFoundException;
import com.acme.bankapp.exceptions.bank.ClientsMaxException;

/**
 * Class stores clients of the bank
 * @author alex
 */
public class Bank {
	private Client[] clients;
	private int clientsCount;
	private static final int CLIENTS_MAX = 10;
	
	/**
	 * The default constructor
	 */
	public Bank() {
		this.clients = new Client[Bank.CLIENTS_MAX];
	}
	
	/**
	 * @param id the client id
	 * @return the client
	 */
	public Client getClient(int id) {
		if (id >= 0 && id <= this.clientsCount) {
			return this.clients[id];
		} else {
			return null;
		}
	}
	
	/**
	 * Adds the client to bank, does not allows to add a client with empty name
	 * @param client the client
	 * @throws ClientsMaxException 
	 */
	public void addClient(Client client) throws ClientsMaxException {
		if (this.clientsCount < Bank.CLIENTS_MAX) {
			this.clients[this.clientsCount++] = client;
		} else {
			throw new ClientsMaxException();
		}
	}
	
	/**
	 * @return the clients count
	 */
	public int getClientsCount() {
		return this.clientsCount;
	}
	
	/**
	 * @param clientId the client id
	 * @return the client account
	 */
	public Account getClientAccaunt(int clientId) {
		Client client = this.getClient(clientId);
		if (client != null) {
			return client.getAccount();
		} else {
			return null;
		}
	}
}
